// @Software: serve
// @File : sys_menu
// @Author : vince
// @Time : 2021/9/19 12:15
// @Description  请填写文件描述
package fake

import (
	"gintify/core"
	"gintify/model"
	"gorm.io/gorm"
)

func FakeMenus() {
	var menus = []model.SysMenu{
		{Meta: model.Meta{Name: "Dashboard", Title: "仪表盘", Icon: "home"}, ParentId: 0, Path: "/dashboard"},
		{Meta: model.Meta{Name: "Manager", Title: "系统管理", Icon: "tune"}, ParentId: 0, Path: "/manage"},
		{Meta: model.Meta{Name: "Role", Title: "角色管理", Icon: "account"}, ParentId: 2, Path: "/role"},
		{Meta: model.Meta{Name: "User", Title: "用户管理", Icon: "account-multiple"}, ParentId: 2, Path: "/user"},
		{Meta: model.Meta{Name: "Menu", Title: "菜单管理", Icon: "menu"}, ParentId: 2, Path: "/menu"},
		{Meta: model.Meta{Name: "Resource", Title: "资源管理", Icon: "semantic-web"}, ParentId: 2, Path: "/resource"},
		{Meta: model.Meta{Name: "Option", Title: "配置管理", Icon: "cog"}, ParentId: 2, Path: "/option"},
		{Meta: model.Meta{Name: "Dictionary", Title: "字典管理", Icon: "book-alphabet"}, ParentId: 2, Path: "/dictionary"},
		{Meta: model.Meta{Name: "Helper", Title: "自助专区", Icon: "animation"}, ParentId: 0, Path: "/helper"},
		{Meta: model.Meta{Name: "Avatar", Title: "头像生成", Icon: "account-star"}, ParentId: 9, Path: "/avatar"},
		{Meta: model.Meta{Name: "Icon", Title: "图标集合", Icon: "star-four-points"}, ParentId: 9, Path: "/icon"},
		{Meta: model.Meta{Name: "Batch", Title: "批量动作", Icon: "star-shooting"}, ParentId: 9, Path: "/batch"},
		//{Meta: model.Meta{Name: "tools", Title: "系统工具", Icon: ""}, ParentId: 0},
		//{Meta: model.Meta{Name: "codes", Title: "自动编码", Icon: ""}, ParentId: 9},
	}

	db := core.DB.Model(&model.SysMenu{})
	_ = db.Transaction(func(tx *gorm.DB) error {
		if tx.First(&model.SysMenu{}).RowsAffected > 0 {
			core.LG.Errorf("SysMenu表不为空")
			return nil
		}
		for _, menu := range menus {
			if err := tx.Create(&menu).Error; err != nil {
				core.LG.Errorf("创建SysMenu失败, %v\n", err)
				return err
			}
		}
		return nil
	})
}
